/* Copyright 2011 Elektrobit Wireless Communications Oy (EB)


  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 2 as 
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


 *All rights reserved 
 *Version:Elektrobit_Qt_1.0.0_20110305 */


#include "photoriverpage.h"
#include <appcommon.h>
#include <servicemanager.h>
#include <QtGui/QApplication>
#include <QDeclarativeEngine>
#include <appcommon.h>
#include <servicemanager.h>
#include <QTimer>
#include <QGraphicsObject>
#include <QDeclarativeItem>
#include <QDir>
#include <QDesktopServices>

QDeclarativeListProperty<ImageData> PhotoRiverPage::imageDatas(){
    return QDeclarativeListProperty<ImageData>(this, &_imageDatas, &imageDatasPropAppend,
            &imageDatasPropCount, &imageDatasPropAt, &imageDatasPropClear);
}

PhotoRiverPage::PhotoRiverPage(QObject *parent) : Page(parent) {
}

int PhotoRiverPage::imageDatasCount()
{
    return _imageDatas.count();

}

int PhotoRiverPage::init() {
    this->mPhotoRiverPageView = qobject_cast<PhotoRiverPageView *>(this->mPageView);
    if(!mPhotoRiverPageView) {
        return -1;
    }

    if(_imageDatas.empty() == false) {
        foreach(ImageData * i, _imageDatas) {
            delete i;
            i = NULL;
        }
        _imageDatas.clear();
    }

    QString indexName ="";
    QString indexImage = "";

    for(int i = 0; i < SERVICE(PicCovertService)->getList()->count(); i++)
    {
        indexName = "";
        indexImage = SERVICE(PicCovertService)->getList()->at(i);
        APPINFO << indexImage;

        _imageDatas.append(new ImageData(indexName, indexImage));
    }
    return 0;
}

int PhotoRiverPage::uninit() {

    return 0;
}

int PhotoRiverPage::beforeShow() {

    this->mPhotoRiverPageView->showViewUseQml(this);
    return 0;
}

int PhotoRiverPage::afterShow() {
    return 0;
}

int PhotoRiverPage::onClick(int key) {
    APPINFO << key;
}

int PhotoRiverPage::onIconClick(QString icon) {
    if(icon == QString("return")) {
        SERVICE(RouterService)->goBack();
        return 0;
    }

}

int PhotoRiverPage::onTouch(const QString &type, const QHash<QString, QString> *args) {
    return 0;
}

void PhotoRiverPage::onClickButton(const QString &buttonName) {
}

void PhotoRiverPage::changeToFilm() {
}


void PhotoRiverPage::changeLanguage() {
}

